<template>
	<view class="content poRel">
		<view class="wid100 dis disAl" style="box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(0,0,0,0.1);height: 107rpx;">
			<view class="wid90 mar dis disAl disJuC borRad40 hei60"style="background: #E5E5E5;">
				<view class="dis disJuC" style="width: 13%;">
					<uni-icons type="search" size="35rpx" color="#AFB6B1"></uni-icons>
				</view>
				<input class="wid85" v-model="sousuo" @input="sousuoInput" 
					placeholder="请输入技师姓名" placeholder-style="color: #AFB6B1;"/>
			</view>
		</view>
		<scroll-view style="height: calc(100vh - 107rpx);" class="wid100" scroll-y="true" @scrolltolower="lower">
			<wsj v-if="list.length == 0" zs='0'></wsj>
			<view style="height: 1rpx;"></view>
			<block v-for="(item,index) in list" :key="index">
				<view class="wid90 mar mar-top30 borRad10" @click="tiaozhuan('/pages/technician/particulars?id='+item.id)"
					style="box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(0,0,0,0.1);">
					<view class="wid90 mar" style="padding: 22rpx 0;">
						<view class="dis disAl">
							<view style="width: 30%;">
								<view class="poRel" style="width: 150rpx;height: 208rpx;">
									<image :lazy-load="true" :src="item.coverimg" style="" class="borRad20 wh100"></image>
									<view class="poAbs dis disAl disJuC coFFF xinren foSi18">新</view>
								</view>
							</view>
							<view style="width: 70%;">
								<view class="dis disAl disJuB liH40">
									<view class="dis disAl">
										<view class="foSi30 fowe600 mar-right20">{{item.name}}</view>
										<!-- <image src="../../static/renzheng.png" class="mar-right20" style="width: 25rpx;height: 25rpx;"></image> -->
										<uni-icons custom-prefix="iconfont" size="26rpx" :color="theme.main_color"
											type="icon-renzhengpeizhi" class="mar-right20"></uni-icons>
										<view class="dis disAl">
											<image src="../../static/pingjia.png" style="width: 27rpx;height: 24rpx;"></image>
											<view class="mar-left10 foSi25">{{item.star}}</view>
										</view>
									</view>
									<view class="foSi20" style="color: #737373;">已服务{{item.service_order_num}}单</view>
								</view>
								<view class="dis disAl flwa" style="color: #00C82D;">
									<block v-for="(item1,index1) in 3" :key="index1">
										<view class="borRad10 mar-top15 mar-right10 tim1 foSi18"
										 :style="'background-color: '+theme.main_color+'21;color: '+theme.main_color+';'">热情</view>
									</block>
								</view>
								<view class="mar-top20 dis disAl disJuB foSi20" style="color: #737373;">
									<view class="dis disAl">
										<view class="dis disAl">
											<image src="../../static/mendian1.png" style="width: 25rpx;height: 22rpx;"></image>
											<view class="mar-left10">{{item.store_name}}</view>
										</view>
										<view class="dis disAl mar-left30">
											<image src="../../static/liulan1.png" style="width: 26rpx;height: 20rpx;"></image>
											<view class="mar-left10">{{item.see_num}}</view>
										</view>
										<view class="dis disAl mar-left30" @click.stop="shouchang(index)">
											<uni-icons v-if="item.collect == 2" type="star-filled" size="30rpx" :color="theme.main_color"></uni-icons>
											<uni-icons v-if="item.collect == 1" type="star" size="30rpx" color="#737373"></uni-icons>
											<view class="mar-left10">{{item.coll_num}}</view>
										</view>
									</view>
									<view class="dis disAl">
										<uni-icons type="location-filled" size="30rpx" :color="theme.main_color"></uni-icons>
										<view class="foSi25 mar-left10">{{item.km}}</view>
									</view>
								</view>
								<view class="mar-top15 dis disJuB foSi20" style="align-items: flex-end;">
									<view class="dis disAl">
										<!-- <image src="../../static/yuyue1.png" style="width: 25rpx;height: 25rpx;"></image> -->
										<uni-icons custom-prefix="iconfont" size="26rpx" :color="theme.seco_color"
											type="icon-shijianguanli1"></uni-icons>
										<view class="mar-left10 fowe600" :style="'color: '+theme.seco_color+';'">最早可约时间{{item.start_time}}</view>
									</view>
									<view class="dis disAl disJuC coFFF borRad20 butt2" :style="'background-color: '+theme.main_color+';'">去下单</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</block>
			<view style="height: 150rpx;"></view>
		</scroll-view>
		<view class="poFix wid100 dis disAl disJuC bacFFF" style="height: 124rpx;border-top: 1rpx solid #878787;bottom: 0;">
			<view class="wid90 borRad40 dis disAl disJuC coFFF foSi35" @click="fanhui()"
				style="height: 85rpx;" :style="'background-color: '+theme.main_color+';'">返回上页</view>
		</view>
	</view>
</template>

<script>
	import wsj from '../common/w_sj.vue'
	export default {
		components: {
			wsj
		},
		data() {
			return {
				url: this.global.url,
				timer: null,
				sousuo: '',
				last_page: 0,
				page: 1,
				id: '',
				list: [],
				theme: null
			}
		},
		onLoad(option) {
			this.id = option.id
			this.theme = uni.getStorageSync('theme')
			this.city = uni.getStorageSync('city');
			this.getList()
		},
		methods: {
			shouchang(index){
				var that = this;
				if(!uni.getStorageSync('token')){
					return uni.showToast({title: '请登录',icon: 'error',duration: 2000}) 
				}
				var type = that.list[index].collect == 1?2:1
				uni.request({
					url: that.global.url + 'api/qianyu_smfw/trends/collect_add',
					method: "POST",
					header: {
						'site-id': that.global.site_id,//自定义请求头信息
						'token': uni.getStorageSync('token')
					},
					data: {
						tech_id: that.list[index].id,
						type: that.list[index].collect
					},
					success(res) {
						let result = res.data
						if (result.code == 1) {
							that.list[index].collect = type
							if(type == 2){
								that.list[index].coll_num += 1
							}else{
								that.list[index].coll_num -= 1
							}
						}else{
							uni.showToast({
								title: result.msg,
								//将值设置为 success 或者直接不用写icon这个参数
								icon: 'error',
								//显示持续时间为 2秒
								duration: 2000
							}) 
						}
					}
				})
			},
			sousuoInput: function(event) {
				var that = this
				if (that.timer !== null) clearTimeout(that.timer)
				that.timer = setTimeout(() => {
					that.sousuo = event.target.value
					that.page = 1
					that.getList()
					console.log(that.sousuo)
				}, 1000)
			},
			getList(){
				var that = this
				uni.showLoading({
					title:'加载中...'
				})
				uni.request({
					url: that.global.url+'api/qianyu_smfw/technician/lists',
					method: 'POST',
					header:{
						'site-id':that.global.site_id
					},
					data: {
						city: that.city.id,
						name: that.sousuo,
						lon: uni.getStorageSync('lon')?uni.getStorageSync('lon'):125.35043,
						lat: uni.getStorageSync('lat')?uni.getStorageSync('lat'):43.86414,
						status: 0,
						page: that.page
					},
					success(res) {
						let result = res.data
						if (result.code == 1) {
							that.last_page = result.data.last_page
							if(that.page == 1){
								that.list = result.data.data
							}else{
								that.list = that.list.concat(result.data.data)
							}
						}else{
							uni.showToast({
								title: result.msg,
								//将值设置为 success 或者直接不用写icon这个参数
								icon: 'error',
								//显示持续时间为 2秒
								duration: 2000
							}) 
						}
					},
					complete() {
						uni.hideLoading()
					}
				})
			},
			lower(e) {
				if(this.last_page > this.page){
					this.page++
					this.getList()
				}
			},
			fanhui(){
				uni.navigateBack(1)
			},
			tiaozhuan(url) {
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>

<style>
	.tim1{
		padding: 6rpx 13rpx;
	}
	.butt2{
		width: 135rpx;
		height: 55rpx;
		border-radius: 10rpx;
	}
	.richImg {
	    width: 100% !important;
	    height: auto !important;
	}
</style>
